#!usr/bin/python


import threading ,time
#constant number
b=50

l = threading.Lock()

def sleepprint():
		#time.sleep(1)
		print "hello from both"


def fun_thread():
		global b
		print "thread name is %s \n"%threading.currentThread().getName()
		l.acquire()
		try:
				print "thread %s  running \n"%threading.currentThread().getName()
				time.sleep(1)
				b=b+50
				print "thread %s set b = %s\n"%(threading.currentThread().getName(),b)
		finally:
				l.release()




t=threading.Thread(target=fun_thread,name="child")
t.setDaemon(1)
t.start()
print "hello from main thread\n"
#time.sleep(1)
#sleepprint()
t.join()



#use lock in the thread

childthreads=[]
for i in range(1,5):
		t=threading.Thread(target=fun_thread,name="thread-%d"%i)
		t.setDaemon(1)
		t.start()
		childthreads.append(t)

for  t in childthreads:
	t.join()
print "final b =%d\n"%b


